$(function() {

    // 轮播图模块
    var swiper = new Swiper('.swiper-container', {
        spaceBetween: 30,
        centeredSlides: true,
        autoplay: {
            delay: 2500,
            disableOnInteraction: false,
        },
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });

    // 登录模块
    getlogin()

    function getlogin() {
        $.ajax({
            method: 'POST',
            url: '/api/login',
            data: {
                username: 'admin',
                password: 'admin'
            },

            success: function(res) {
                if (res.status !== 0) {
                    return console.log(res.message);
                }
                // console.log(res);
                // console.log(res.token);
                localStorage.setItem('token', res.token)

            }
        })
    }


    // 渲染轮播图模块
    getlunbo()

    function getlunbo() {
        $.ajax({
            method: 'GET',
            url: '/admin/swipers',

            success: function(res) {
                if (res.status !== 0) {
                    return console.log(res.message);
                }
                console.log(res);
                renderbanner(res)
            }
        })
    }

    function renderbanner(res) {
        let htmlStr = template('banner-html', res)
        $('#banner_kr').html(htmlStr)
    }


    // 渲染合作伙伴
    getlink()

    function getlink() {
        $.ajax({
            method: 'GET',
            url: '/api/links',

            success: function(res) {
                if (res.status !== 0) {
                    return console.log(res.message);
                }
                console.log(res);
                renderlink(res)
            }
        })
    }

    function renderlink(res) {
        let htmlStr = template('link-html', res)
        $('.kr_collaborator').html(htmlStr)
    }


})